<template>
  <div class='goods_list'>
    <router-link :to='"goodsInfo/" + item.id' class='goods-item' v-for="item in goodsList" :key="item.id" tag="div">
      <img :src="item.url[0]"/>
      <h1 class="title">{{ item.name }}</h1>
      <div class="info">
        <p class="price">
          <span class="now">¥{{ item.new_price }}</span>
          <span class="old">¥{{ item.old_price }}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩余{{ item.inventory }}件</span>
        </p>
      </div>
    </router-link>
  </div>
</template>

<script>
import { Toast } from 'mint-ui'

export default{
  data () {
    return {
      goodsList: []
    }
  },
  created () {
    this.getGoodsList()
  },
  methods: {
    getGoodsList () {
      this.$http.get('api/getGoods').then(result => {
        if (result.status === 200) {
          this.goodsList = result.data
        } else {
          Toast('获取商品信息失败!')
        }
      })
    }
  }
}
</script>

<style scoped>
  .goods_list{
    display: flex;
    flex-wrap: wrap;
    padding: 4px;
  }
  .goods-item{
    width: 47%;
    margin: 4px;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  .goods-item img{
    width: 100%;
  }
  .goods-item .title{
    font-size: 14px;
  }
  .info{
    background-color: #eee;
  }
  .info .price .now{
    font-size: 14px;
    font-weight: bold;
    color: red;
  }
  .info .price .old{
    font-size: 13px;
    text-decoration: line-through;
    margin-left: 30px;
  }
  .info .sell{
    display: flex;
    justify-content: space-between;
    font-size: 12px;
  }
</style>
